package by.myteam.gonki.states.movementstates;

import by.myteam.gonki.bo.car.SelectCar;
import by.myteam.gonki.logic.GameLogic;

public class RightMovementState implements IMovementState {

        private int dv = 1;
        private int dvControler = 0;
        
        @Override
        public void move() {
                dvControler++;
                checkOnSpeed(-1, 2, 2);
                checkOnSpeed(2, 3, 4);
                checkOnSpeed(3, 4, 13);
                checkOnSpeed(4, 4.5, 25);
                checkOnSpeed(4.5, 5, 45);

        }

        @Override
        public void undo() {
                GameLogic.INSTANCE.setDSpeed(0);
        }

        public void checkOnSpeed(double mult1, double mult2, int min) {
                if (GameLogic.INSTANCE.getSpeed() > mult1
                                * SelectCar.INSTANCE.getCar().getMaxSpeed() / 5
                                && GameLogic.INSTANCE.getSpeed() <= mult2
                                                * SelectCar.INSTANCE.getCar().getMaxSpeed() / 5
                                && dvControler >= min) {
                        GameLogic.INSTANCE.setDSpeed(dv);
                        dvControler = 0;
                }
        }
}